/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.lottery.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.lottery.entity.ActivityStatus;
import com.thinkgem.jeesite.modules.lottery.service.ActivityStatusService;

/**
 * 活动状态管理Controller
 * @author Muser
 * @version 2019-07-31
 */
@Controller
@RequestMapping(value = "${adminPath}/lottery/activityStatus")
public class ActivityStatusController extends BaseController {

	@Autowired
	private ActivityStatusService activityStatusService;
	
	@ModelAttribute
	public ActivityStatus get(@RequestParam(required=false) String id) {
		ActivityStatus entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = activityStatusService.get(id);
		}
		if (entity == null){
			entity = new ActivityStatus();
		}
		return entity;
	}
	
	@RequiresPermissions("lottery:activityStatus:view")
	@RequestMapping(value = {"list", ""})
	public String list(ActivityStatus activityStatus, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ActivityStatus> page = activityStatusService.findPage(new Page<ActivityStatus>(request, response), activityStatus); 
		model.addAttribute("page", page);
		return "modules/lottery/activityStatusList";
	}

	@RequiresPermissions("lottery:activityStatus:view")
	@RequestMapping(value = "form")
	public String form(ActivityStatus activityStatus, Model model) {
		model.addAttribute("activityStatus", activityStatus);
		return "modules/lottery/activityStatusForm";
	}

	@RequiresPermissions("lottery:activityStatus:edit")
	@RequestMapping(value = "save")
	public String save(ActivityStatus activityStatus, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, activityStatus)){
			return form(activityStatus, model);
		}
		activityStatusService.save(activityStatus);
		addMessage(redirectAttributes, "保存活动状态成功");
		return "redirect:"+Global.getAdminPath()+"/lottery/activityStatus/?repage";
	}
	
	@RequiresPermissions("lottery:activityStatus:edit")
	@RequestMapping(value = "delete")
	public String delete(ActivityStatus activityStatus, RedirectAttributes redirectAttributes) {
		activityStatusService.delete(activityStatus);
		addMessage(redirectAttributes, "删除活动状态成功");
		return "redirect:"+Global.getAdminPath()+"/lottery/activityStatus/?repage";
	}

}